-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
63-9kyo-hwang #218
63-9kyo-hwang #218
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ§μ§ μ΄ λ¬Έμ λ₯Ό μ... κ·Έ NHN μν λλ μ΄λ²λ²λλμ§.. νκ° λλκ΅°μ..
n, m = map(int, input().split())
numbers = list(map(int, input().split()))
start = 0
end = max(numbers) - min(numbers)
def can_do(target):
m_count = 1
min_value = numbers[0]
max_value = numbers[0]
for number in numbers[1:]:
min_value = min(min_value, number)
max_value = max(max_value, number)
if max_value - min_value > target:
m_count += 1
min_value = number
max_value = number
if m_count > m:
return False
return True
while start <= end:
mid = (start + end) // 2
if can_do(mid):
end = mid - 1
else:
start = mid + 1
print(start)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄μ§ νμμΈκ±Έ μκ³ νμ΄λ λμ§ λμ ν λͺ¨λ₯΄κ² μ΄μ κ΅¬κ° λλκΈ° 1 ν΄κ²°νκ³ μμΌμ§ νλ€κ°....
κ·Έ λ¬Έμ λ DPλΌμ κ·Έμ μκ°λ§ νν λ λ Έμ΅λλ€...π₯²
μ μ μ°¨μ΄λ₯Ό μ΄μ©ν΄μ μ΄μ§ νμμ νλ건 μ ν μκ° λͺ»ν λ°©λ²μ΄λ€μπ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ¬Έμ λ₯Ό μ΅λν μ΄ν΄ν΄λ³΄λ €κ³ λ
Έλ ₯νμΌλ λ무 μ΄λ ΅λ€μ..π
μ΄μ§νμμΌλ‘ ν μ μλ€κ³€ μκ° λͺ»νλλ° μ΄μ§νμμΌλ‘ ν리λ€λ μ§μ§ μκ³ λ¦¬μ¦ λ무 μ΄λ €μμ..!!
μκ³ λ§μΌμ
¨μ΅λλ€ππ»β¨
π λ¬Έμ λ§ν¬
κ΅¬κ° λλκΈ° 2
βοΈ μμλ μκ°
1μκ° νΈλΌμ΄νκ³ λ νΌλ°μ€ νμΈ
β¨ μλ μ½λ
1. λ¬Έμ
Nκ°μ μλ‘ μ΄λ£¨μ΄μ§ 1μ°¨μ λ°°μ΄μ΄ μλ€. μ΄ λ°°μ΄μ Mκ° μ΄νμ ꡬκ°μΌλ‘ λλμ΄μ ꡬκ°μ μ μμ μ΅λκ°μ μ΅μλ‘ νλ €κ³ νλ€. ꡬκ°μ λ€μκ³Ό κ°μ 쑰건μ λ§μ‘±ν΄μΌ νλ€.
ꡬκ°μ μ μλ ꡬκ°μ μν μμ μ΅λκ°κ³Ό μ΅μκ°μ μ°¨μ΄μ΄λ€.
μλ₯Ό λ€μ΄, λ°°μ΄μ΄ [1, 5, 4, 6, 2, 1, 3, 7] μ΄κ³ , M = 3μΈ κ²½μ°κ° μλ€.
μ΄λ, [1, 5], [4, 6, 2], [1, 3, 7]λ‘ κ΅¬κ°μ λλλ©΄ κ° κ΅¬κ°μ μ μλ 4, 4, 6μ μ΄ λλ€. μ΄λ, μ΅λκ°μ 6μ μ΄λ€.
λ§μ½, [1, 5, 4], [6, 2, 1], [3, 7]λ‘ κ΅¬κ°μ λλμλ€λ©΄, κ° κ΅¬κ°μ μ μλ 4, 5, 4μ μ΄ λκ³ , μ΄λ μ΅λκ°μ 5μ μ΄ λλ€.
λ κ²½μ° μ€μμ μ΅λκ°μ΄ μ΅μμΈ κ²μ 5μ μΈ κ²μ΄κ³ , 5μ λ³΄λ€ μ΅λκ°μ μκ² λ§λλ λ°©λ²μ μλ€.
λ°°μ΄κ³Ό Mμ΄ μ£Όμ΄μ‘μ λ, ꡬκ°μ μ μμ μ΅λκ°μ μ΅μκ°μ ꡬνλ νλ‘κ·Έλ¨μ μμ±νμμ€.
2. νμ΄
Mκ° μ΄νμ ꡬκ°μΌλ‘ λ°°μ΄μ λλ μΌ νλλ°, μ΄λ₯Ό 무μνκ² λ€ λ€λ£¨κΈ°μ κ²½μ°μ μκ° λ무 λ§λ€. λ¨μν Mμ΄ μ΅λ NκΉμ§ κ°κΈ°λ νκ³ , μ¬μ§μ΄ M "μ΄ν"μ΄κΈ° λλ¬Έμ κ²½μ°μ μλ νλ°μ μΌλ‘ λμ΄λλ€.
λ¬Έμ μμ ꡬνκ³ μ νλ 건 κ΅¬κ° μ μ μ΅λκ° μ€ μ΅μκ°μΈλ°, μ¬κΈ°μ κ΅¬κ° μ μ(ν΄λΉ ꡬκ°μ μ΅λκ° - μ΅μκ°)μ μ£Όλͺ©νλ€.
μ΄ μ μ μ°¨μ΄λ₯Ό νμμ keyλ‘ νμ¬, "μ 체 λ°°μ΄μ Mκ° μ΄νλ‘ λΆν ν μ μλ" κ²λ€ μ€ κ°μ₯ μμ μ μλ₯Ό ꡬν΄λ΄λ©΄ μ λ΅μ΄λ€. μ΄ λ "μ΄μ§ νμ"μΌλ‘ μννλ€. κ·Έλ¬λ©΄ μκ° λ³΅μ‘λλ$Nlog(N)$ μΌλ‘ μΆ©λΆν ν΄κ²° κ°λ₯νλ€.
ꡬκ°μ μ μ μ°¨μ΄λ μ΅μ 0μ (κ΅¬κ° λ΄ λͺ¨λ μ«μκ° λμΌν¨)λΆν° μ΅λ 9999μ (λ°°μ΄μ μλ μ΅μ 1, μ΅λ 10000)μ΄λ€. μ΄ λ²μ λ΄μμ νκ² μ μλ₯Ό μ°Ύμλ³Έλ€. μ΄κΈ°κ°μ Maxμ΄λ€.
μ νμ μΈ μ΄μ§νμ λ‘μ§μ΄λ€. IsValid() ν¨μμ κ²°κ³Όκ° trueμ΄λ©΄ 쑰건μ λΆν©ν μΆμ μ μλΌ μ΄λ₯Ό minimum update μννλ€.
ν΅μ¬ λ‘μ§μ΄λ€. μλ₯Ό λ€μ΄λ³΄μ: [1, 5, 4, 6, 2, 1, 3, 7], M = 3
λ°λΌμ μ λ΅μ 5μ΄λ€.
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ΄ λ¬Έμ λ 2024 NHN κ²μ κ³΅μ± μ½λ© ν μ€νΈ λ¬Έμ μ μ μ¬νλ€(λμ€μ½λμ κ΄λ ¨ ν¬μ€νΈκ° μμΌλ λ§κ΄λΆ!).
μ½ν μΉ λΉμμλ μ΄λ€ μ νμΈμ§ νμ νμ§ λͺ»ν΄ λͺ» νμλλ° @mjj111 λμ΄ "μ΄κ±° μ΄μ§νμμ!" ν΄μ λμ λΆμ ν€κ³ λ°±μ€ λ€μ Έλ³΄λ λΉμ·ν κ² μ΄ λ¬Έμ μλ€.
νΈλΌμ΄ ν΄λ΄€μ§λ§... 1μκ° λμ κ°λ λͺ»μ‘κ³ λ νΌλ°μ€ νμΈνκ³ λμμΌ κ²¨μ°κ²¨μ° λμ μΌ μ μμλ...
νλμ λ°±νΈλνΉ/μ΄μ§νμ/그리λ/DP μμ£Όλ‘ νμ΄μΌκ² λ€.
p.s. μ°Έκ³ λ‘ μ΄ λ¬Έμ λ Nμ ν¬κΈ°κ° μμ΄μ λ€μκ³Ό κ°μ΄ μ ν νμμ ν΄λ ν΅κ³Όνλ€.
(μκ° μ ννμ, μλκ° μ΄μ§νμ)